#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/25 11:39
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : corner_detection.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage.feature import corner_harris, corner_subpix, corner_peaks
from skimage.io import imread
import matplotlib.pyplot as plt

IM_PATH = "../experiment_fig/building.jpg"
im = imread(IM_PATH)
gray_im = im[:, :, 0]
response_image = corner_harris(gray_im)
coordinate_array = corner_peaks(response_image, threshold_rel=0.001)  # (2959, 2)
subpixel_coordinates = corner_subpix(gray_im, coordinate_array)
im_dict = {"corner peaks": coordinate_array, "corner subpixel ": subpixel_coordinates}
position = 1
for title, coordinate in im_dict.items():
    plt.subplot(1, 2, position)
    plt.title(title)
    plt.imshow(im, cmap="gray")
    plt.scatter(coordinate[:, 1], coordinate[:, 0], color="red", s=2)
    plt.axis("off")
    position += 1
plt.show()
